{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "21a1f48e",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "\n",
    "# 1. 人脸识别概念和基础\n",
    "\n",
    "# 2. 人脸识别应用\n",
    "\n",
    "# 3. 人脸识别实践-face++\n",
    "\n",
    "> 1. 人脸检测\n",
    "> 2. 人脸对比+人脸搜索\n",
    ">> 1. 人脸集合创建\n",
    ">> 2. 人脸\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "330ac667",
   "metadata": {},
   "source": [
    "# 人脸识别概念和基础"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "81372267",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "50bc1495",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1678679723,95ad77f5-0fa7-417b-95f4-77d2721d17a7', 'time_used': 178, 'faces': [{'face_token': 'f5a0451499a0e40433617add48ae144f', 'face_rectangle': {'top': 216, 'left': 127, 'width': 247, 'height': 247}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 23}, 'smile': {'value': 0.008, 'threshold': 50.0}, 'headpose': {'pitch_angle': 15.08355, 'roll_angle': 15.235324, 'yaw_angle': -13.442406}, 'blur': {'blurness': {'value': 1.134, 'threshold': 50.0}, 'motionblur': {'value': 1.134, 'threshold': 50.0}, 'gaussianblur': {'value': 1.134, 'threshold': 50.0}}, 'emotion': {'anger': 0.001, 'disgust': 0.001, 'fear': 0.003, 'happiness': 0.008, 'neutral': 99.912, 'sadness': 0.073, 'surprise': 0.001}, 'facequality': {'value': 48.984, 'threshold': 70.1}, 'beauty': {'male_score': 89.123, 'female_score': 90.702}}}], 'image_id': 'MFDmTjSFLrP06qtkm8bpJQ==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸检测\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('蔡徐坤.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2.酬载准备\n",
    "payload = {\n",
    "    'api_key':'S3pPsuiHUq8aTVfx5PaN0i9E9A6qZYG2',\n",
    "    'api_secret':'Ikh4sAg-OyGE53GUI-PNZ1fxwEyL1BeK',\n",
    "    'image_base64':img,\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,emotion,blur,beauty'\n",
    "}\n",
    "\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7de340f9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
